﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStandardItemModel>
#include <QTreeWidgetItem>
#include "SerialPort.h"
#include "PhaseIdentify.h"
#include "SearchTable.h"

namespace Ui {
	class MainWindow;
}

class AreaIdentify;

class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	explicit MainWindow(QWidget* parent = 0);
	~MainWindow();

	void initSerialPort();
	void initWindowElement();
	void initPhaseIdentifyResultView();
	void conectSignalSlot();

	void updateAreaViewModel(const QString& nodeAddr, const QString& nodeStatus, const QString& terminalNo);
	void exportAreaIdentifyResult();
	void updatePhaseViewModel(const QString& nodeAddr, const QString& phaseSequenceType, const QString& physicalPhase, const std::vector<uint32_t>& phaseCnt);
	void exportPhaseIdentifyResult();
	void updateSearchTableViewModel(const QString& nodeAddr);
	void exportSearchTableResult();

	void saveToExcel(QStandardItemModel* model, int columnNum);

	Ui::MainWindow* getUi();
	std::shared_ptr<AreaIdentify> getAreaIdentify();
	std::shared_ptr<PhaseIdentify> getPhaseIdentify();
	std::shared_ptr<SearchTable> getSearchTable();

public slots:
	void receiveLogin();
	void handleComNoCheckBoxToggled(bool checked);
	void handleFunctionaListTreeWidgetItemClicked(QTreeWidgetItem* item, int column);

private:
	Ui::MainWindow* ui;

	QStandardItemModel* areaIdentifyResultViewModel;
	QStandardItemModel* phaseIdentifyResultViewModel;
	QStandardItemModel* searchTableResultViewModel;

	std::shared_ptr<SerialPort> serialPort;

	std::shared_ptr<AreaIdentify> areaIdentify;
	std::shared_ptr<PhaseIdentify> phaseIdentify;
	std::shared_ptr<SearchTable> searchTable;
	std::vector<QString> phaseStatisticsTitle = { "A相：", "B相：", "C相：",  "三相：", "其它：" };
};

#endif // MAINWINDOW_H
